package GUI;

import javax.swing.JFrame;
import javax.swing.JTextField;
import java.awt.BorderLayout;

import javax.swing.ComboBoxModel;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;
import javax.swing.JPanel;
import java.awt.Font;
import javax.swing.JTable;
import java.awt.Label;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.border.LineBorder;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.table.TableModel;
import sql.Test;
import sql.UserDetail;


import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;

import javax.swing.JTextPane;

import logic.CustomerOrdersLog;
import logic.Customers;
import logic.Items;
import logic.Report;
import logic.Suppliers;
import logic.SuppliersOrders;
import logic.Users;
import javax.swing.JPopupMenu;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JInternalFrame;

import org.jfree.ui.RefineryUtilities;

import com.toedter.calendar.JDayChooser;
import com.toedter.calendar.JCalendar;
import java.awt.Button;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;




public class mainscreen extends JFrame {
	int gg=0;
	int indexOfRowToBeDeletedOrderTable;
	int orderPrice,orderPriceCus;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTable table_1;
	private JTable table_4;
	private int i=0;
	public JPanel reportpanel;
	 Vector<Vector<String>> dataCustomers = new Vector<Vector<String>>();
	 Vector<Vector<String>> dataSupOrders = new Vector<Vector<String>>();
	 Vector<Vector<String>> dataCusOrders = new Vector<Vector<String>>();
	 Vector<String> headersSupOrders = new Vector<String>();
	 Vector<String> headersCusOrders = new Vector<String>();
	 Vector<String> headersSupOrdersTO = new Vector<String>();
	 Vector<String> headersCusOrdersTO = new Vector<String>();
	 Vector<String> headersCus = new Vector<String>();
	 Vector<String> headers = new Vector<String>();
	 Vector<String> headersSup = new Vector<String>();
	 Vector<String> headersinventory = new Vector<String>();
	 Vector<Vector<String>> data = new Vector<Vector<String>>();
	 Vector<Vector<String>> dataSuppliers = new Vector<Vector<String>>();
	 Vector<Vector<String>> dataSuppliersOrder = new Vector<Vector<String>>();
	 Vector<Vector<String>> dataCustomersOrder = new Vector<Vector<String>>();
	 Vector<Vector<String>> items = new Vector<Vector<String>>();
	 Vector<Vector<String>> inventory = new Vector<Vector<String>>();
	 Vector<String> itemsheader = new Vector<String>();
	 ArrayList<String> res1;
	 
	 Vector<String> reportheadr = new Vector<String>();
	 Vector<Vector<String>> report_table = new Vector<Vector<String>>();
	 
	private JTable table_6;
	private JTable table_7;
	private JTextField password;
	private JTextField repassword;
	private JTextField lastname;
	private JTextField address;
	private JTextField email;
	private JTextField name;
	private JTextField username;
	private JTextField telephone;
	private JTextField textField_4;
	private JTextField textField_5;
	private JTextField textField_6;
	private JTextField textField_7;
	private JTextField textField_8;
	private JTextField textField_9;
	private JTextField textField_10;
	private JTextField textField_11;
	private JTextField textField_12;
	private JTextField textField_41;
	private JTextField textField_51;
	private JTextField textField_61;
	private JTextField textField_71;
	private JTextField textField_81;
	private JTextField textField_91;
	private JTextField textField_101;
	private JTextField textField_111;
	private JTextField textField_121;
	private JTextField txtitemname;
	private JTextField txtdesc;
	private JTable itemtable;
	private JTextField Quantity;
	private JTable table_8;
	private JTable table_Customers;
	private JTable table_sup_orders;
	private JTable table_cus_orders;
	private JTable table;
	private JTextField textField_PriceUnit;
	private JTextField orderSum;
	private JTable inventory_table;
	private JTextField txtshelf;
	private JTable reporttable;
	private JTable templeCusOrder;
	private JTextField textFieldPricePerUnitCus;
	private JTextField textFieldQuantityCus;
	private JTextField orderSumCus;
	private JTextField txttotalprice;
	public String permition1;
	public mainscreen(final String permition,String first,String last) throws SQLException {
		this.permition1=permition;
		getContentPane().setLayout(null);
		
		Users us = new Users();
		
		ArrayList<String> res= us.getusers();
		
		for (int i=0; i<=(res.size())-6;i=i+6)
		{
	        Vector<String> row = fill_table(res, i);
	       
	         data.add(row);
	    }
		
		//System.out.println(permition);
		
	     headers.add("User Name");
	     headers.add("First Name");
	     headers.add("Last Name");
	     headers.add("Email");
	     headers.add("Tel");
	     headers.add("Address");
	     //create item table
	     Items it = new Items();
		    
		    ArrayList<String> itemres = null;
			try {
				itemres = it.getitems();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}	
			for (int i=0; i<=(itemres.size())-4;i=i+4)
			{
		     Vector<String> row = fill_table_items(itemres, i);
		       
		         items.add(row);
		         
		    }
			//System.out.print(items);
			 itemsheader.add("ID");
		     itemsheader.add("Name");
		     itemsheader.add("Description");
		     itemsheader.add("Menufactor");
		   //create inverntory table  
		     ArrayList<String> inventoryres = null;
				try
				{
					inventoryres = it.getimventory();
				} 
				catch (SQLException e) 
				{
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	
				for (int i=0; i<=(inventoryres.size())-4;i=i+4)
				{
			     Vector<String> row = fill_table_inventory(inventoryres, i);
			       
			     	inventory.add(row);
			         
			    }
				//System.out.print(items);
				headersinventory.add("ID");
				headersinventory.add("Name");
				headersinventory.add("Quantity");
				headersinventory.add("Shelf");
			    
		
				
				reportheadr.add("Order ID");
				reportheadr.add("Supplier name");
				reportheadr.add("Start date");
				reportheadr.add("End date");
				reportheadr.add("Price");
				reportheadr.add("Status");
				
		textField = new JTextField();
		textField.setBounds(728, 11, 122, 28);
		getContentPane().add(textField);
		textField.setColumns(10);
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setFont(new Font("Tahoma", Font.BOLD, 15));
		tabbedPane.setBounds(21, 90, 936, 515);
		getContentPane().add(tabbedPane);
		
		JPanel dashboard = new JPanel();
		tabbedPane.addTab("Dashboard", null, dashboard, null);
		dashboard.setLayout(null);
		
		JLabel lblhello = new JLabel("Hello"+" "+first);
		lblhello.setFont(new Font("Tahoma", Font.PLAIN, 15));
		lblhello.setBounds(32, 31, 102, 38);
		dashboard.add(lblhello);
		
		JPanel orderpanel = new JPanel();
		tabbedPane.addTab("Suppliers Orders", null, orderpanel, null);
		orderpanel.setLayout(null);
		
		final JInternalFrame orderframe = new JInternalFrame("Add Order",true,true,true,true);
		orderframe.setBounds(21, 11, 681, 415);
		orderframe.getContentPane().setFont(new Font("Tahoma", Font.PLAIN, 14));
		orderpanel.add(orderframe);
		orderframe.getContentPane().setLayout(null);
		
		
		final JLabel lblNewLabel = new JLabel("Supplier Name");
		lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblNewLabel.setBounds(10, 29, 99, 24);
		orderframe.getContentPane().add(lblNewLabel);
		
		final JComboBox<String> supnamebox = new JComboBox<String>();
		updateSupCombo(supnamebox);
		
		supnamebox.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
			}
		});
		supnamebox.setBounds(119, 32, 114, 22);
		orderframe.getContentPane().add(supnamebox);
		
		final JLabel lblNewLabel_1 = new JLabel("Item");
		lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblNewLabel_1.setBounds(10, 80, 99, 17);
		orderframe.getContentPane().add(lblNewLabel_1);
		
		final JComboBox<String> itemsBox = new JComboBox<String>();
		ArrayList<String> arrIL=new ArrayList<String>();
		Items comboItem =new  Items();
		arrIL=comboItem.getItemNmesList();
		for(int i=0;i<arrIL.size();i+=2)
		{
			itemsBox.addItem(arrIL.get(i)+"-"+arrIL.get(i+1));
		}
		itemsBox.setBounds(118, 79, 115, 22);
		orderframe.getContentPane().add(itemsBox);
		
		
		
		final JLabel lblQuantity_1 = new JLabel("Quantity");
		lblQuantity_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblQuantity_1.setBounds(10, 167, 99, 17);
		orderframe.getContentPane().add(lblQuantity_1);
		
		Quantity = new JTextField();
		Quantity.setBounds(119, 167, 114, 20);
		orderframe.getContentPane().add(Quantity);
		Quantity.setColumns(10);

		headersSupOrdersTO.add("Supplier name");
		headersSupOrdersTO.add("Item name");
		headersSupOrdersTO.add("Quantity");
		headersSupOrdersTO.add("Price");
		
		final JButton btnCloseOrder = new JButton("Complete Order");
		btnCloseOrder.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
		
				ArrayList<String> supOrderO= new  ArrayList<String>();
				supOrderO.add((String) supnamebox.getSelectedItem());
				supOrderO.add(Integer.toString(orderPrice));
				
			SuppliersOrders soadd = new SuppliersOrders();	
			soadd.openSupOrder(supOrderO,dataSuppliersOrder);	
			dataSuppliersOrder.clear();
			orderframe.setVisible(false);
			updateOrdersTable();
			
			}
		});
		btnCloseOrder.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnCloseOrder.setBounds(509, 327, 136, 39);
		orderframe.getContentPane().add(btnCloseOrder);
		
		final JButton btnAddToOrder = new JButton("Add to order");
		btnAddToOrder.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
			if( isNumeric(Quantity.getText())&&isNumeric(textField_PriceUnit.getText()))
				{
				
				String supName=(String) supnamebox.getSelectedItem();
				String itemName =(String) itemsBox.getSelectedItem();
				String quantityOfItems=Quantity.getText();
				String priceOfItem=textField_PriceUnit.getText();
				String AllPrice;
				int price=Integer.parseInt(quantityOfItems)*Integer.parseInt(priceOfItem);
				orderPrice+=price;
				AllPrice=Integer.toString(price);
				Vector<String> rowso = new Vector<String>();
				rowso.add(supName); 
				rowso.add(itemName);
				rowso.add(quantityOfItems);
				rowso.add(AllPrice);
				dataSuppliersOrder.add(rowso);
				DefaultTableModel model11 = (DefaultTableModel) table_8.getModel();
				model11.fireTableDataChanged();
				orderSum.setText(String.valueOf(orderPrice));
				supnamebox.disable();
				}
			else JOptionPane.showMessageDialog(null, "Please enter only digits");	
			}
		});
		btnAddToOrder.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnAddToOrder.setBounds(48, 208, 166, 33);
		orderframe.getContentPane().add(btnAddToOrder);
		
		
		JScrollPane scrollPane_3 = new JScrollPane();
		scrollPane_3.setBounds(262, 23, 383, 293);
		orderframe.getContentPane().add(scrollPane_3);
		
		table_8 = new JTable(dataSuppliersOrder,headersSupOrdersTO)
		{
			private static final long serialVersionUID = 1L;
			public boolean isCellEditable(int data, int columns)
            {
                if(columns>=1)
         	     return false;
                else return true;
            }
		};
		scrollPane_3.setViewportView(table_8);
		
		final JButton btnDeleteFromOrder = new JButton("Delete items");
		btnDeleteFromOrder.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(table_8.getSelectedRow()>=0)
				{
					Vector<String> tempvect = new Vector<String>();
					tempvect=dataSuppliersOrder.get(table_8.getSelectedRow());
					orderPrice-=Integer.parseInt(tempvect.get(3));
					orderSum.setText(String.valueOf(orderPrice));
		        	dataSuppliersOrder.remove(table_8.getSelectedRow());   
		        	DefaultTableModel model111 = (DefaultTableModel) table_8.getModel();
		        	model111.fireTableDataChanged();
				}
			}
		});
		btnDeleteFromOrder.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnDeleteFromOrder.setBounds(48, 252, 166, 33);
		orderframe.getContentPane().add(btnDeleteFromOrder);
		
		final JLabel lblPricePerUnit = new JLabel("Price per unit");
		lblPricePerUnit.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblPricePerUnit.setBounds(10, 125, 99, 17);
		orderframe.getContentPane().add(lblPricePerUnit);
		
		textField_PriceUnit = new JTextField();
		textField_PriceUnit.setColumns(10);
		textField_PriceUnit.setBounds(119, 125, 114, 20);
		orderframe.getContentPane().add(textField_PriceUnit);
		
		final JLabel lblNewLabel_4 = new JLabel("Total sum:");
		lblNewLabel_4.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblNewLabel_4.setBounds(262, 341, 114, 14);
		orderframe.getContentPane().add(lblNewLabel_4);
		
		orderSum = new JTextField();
		orderSum.setFont(new Font("Tahoma", Font.PLAIN, 14));
		orderSum.setBounds(337, 336, 114, 20);
		orderframe.getContentPane().add(orderSum);
		orderSum.setColumns(10);
		
		final JLabel lblOrderStatus = new JLabel("Order Status");
		lblOrderStatus.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblOrderStatus.setBounds(10, 36, 99, 14);
		orderframe.getContentPane().add(lblOrderStatus);
		
		final JComboBox statusbox = new JComboBox();
		
		if(permition.equals("1") || permition.equals("2")){
			statusbox.setModel(new DefaultComboBoxModel(new String[] {"Initialize", "Departured", "Working out", "order in warehouse", "closed"}));
		}
		else
			statusbox.setModel(new DefaultComboBoxModel(new String[] {"order in warehouse"}));
		
		statusbox.setFocusable(false);  
		statusbox.setBounds(119, 33, 114, 20);
		orderframe.getContentPane().add(statusbox);
		
		final JButton btnUpdateStatus = new JButton("Update Status");
		btnUpdateStatus.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				int status=statusbox.getSelectedIndex();
				//int y = table_sup_orders.getSelectedColumn();
				int x = table_sup_orders.getSelectedRow();
				int flag ;
				if(x >-1)
				{
					ArrayList<String> arrs =new ArrayList<>();
					arrs.clear();
					Object obj = table_sup_orders.getModel().getValueAt(x, 0);
					SuppliersOrders so = new SuppliersOrders();
					arrs.add(obj.toString());
					arrs.add(statusbox.getSelectedItem().toString());
					flag = so.updateorderstatus(arrs,permition1);
					if(flag==1)
					{
						updateOrdersTable();
						orderframe.setVisible(false);
						JOptionPane.showMessageDialog(null, "Status Updated Succesfuly");
						updateinventorytable();
						
					}
					else if(flag==3)
						JOptionPane.showMessageDialog(null, "Only the manager can change the status");
					else
					{
						JOptionPane.showMessageDialog(null, "Error eccured , Please try again");						
					}
					
					
				}
			}
		});
		btnUpdateStatus.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnUpdateStatus.setBounds(48, 208, 166, 30);
		orderframe.getContentPane().add(btnUpdateStatus);
		
		JScrollPane scrollPane_2 = new JScrollPane();
		scrollPane_2.setBounds(21, 24, 681, 330);
		orderpanel.add(scrollPane_2);
		
		headersSupOrders.add("Order ID");
		headersSupOrders.add("Supplier name");
		headersSupOrders.add("Start date");
		headersSupOrders.add("End date");
		headersSupOrders.add("Price");
		headersSupOrders.add("Status");
		
		orderframe.setVisible(false);
		
		SuppliersOrders supO = new SuppliersOrders();
		ArrayList<String> resso= supO.getSuppliersOrders();
		for (int i=0; i<=(resso.size())-6;i=i+6)
		{
			Vector<String> rowso = new Vector<String>();
				rowso.add(resso.get(i)); 
				rowso.add(resso.get(i+1));
				rowso.add(resso.get(i+2));
				rowso.add(resso.get(i+3));
				rowso.add(resso.get(i+4));
				rowso.add(resso.get(i+5));
				dataSupOrders.add(rowso);
		}
		
		table_sup_orders  = new JTable(dataSupOrders,headersSupOrders)
		{
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			public boolean isCellEditable(int data, int columns)
            {
                if(columns>=1)
         	     return false;
                else return true;
            }
		};

		scrollPane_2.setViewportView(table_sup_orders);
		table_sup_orders.setAutoCreateRowSorter(true);
		
			JButton addorederopen = new JButton("Add Order");
			
			if(permition.equals("1") || permition.equals("2")){
				addorederopen.setEnabled(true);
			}
			else
				addorederopen.setEnabled(false);
			
			
			addorederopen.setBounds(212, 361, 105, 33);
			addorederopen.addActionListener(new ActionListener() {
				@SuppressWarnings("deprecation")
				public void actionPerformed(ActionEvent arg0) {
					supnamebox.enable();
					lblOrderStatus.setVisible(false);
					btnUpdateStatus.setVisible(false);
					statusbox.setVisible(false);
					lblNewLabel.setVisible(true);
					supnamebox.setVisible(true);
					lblNewLabel_1.setVisible(true);
					itemsBox.setVisible(true);
					lblQuantity_1.setVisible(true);
					lblQuantity_1.setVisible(true);
					btnCloseOrder.setVisible(true);
					btnAddToOrder.setVisible(true);
					btnDeleteFromOrder.setVisible(true);
					lblNewLabel_4.setVisible(true);
					orderSum.setVisible(true);
					lblPricePerUnit.setVisible(true);
					textField_PriceUnit.setVisible(true);
					Quantity.setVisible(true);
					orderframe.setVisible(true);
					orderPrice=0;
					dataSuppliersOrder.clear();
					Quantity.setText("");
					textField_PriceUnit.setText("");
					
				}
			});
			addorederopen.setFont(new Font("Tahoma", Font.PLAIN, 14));
			
			
			orderpanel.add(addorederopen);
		JButton watchorderopen = new JButton("Watch Order");
		
		watchorderopen.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				//int y = table_sup_orders.getSelectedColumn();
				int x = table_sup_orders.getSelectedRow();
				
				
				if( x>-1)
				{
					ArrayList<String> arrs =new ArrayList<>();
					arrs.clear();
					Object obj = table_sup_orders.getModel().getValueAt(x, 0);
					
					SuppliersOrders so = new SuppliersOrders();
					arrs=so.getorderfromdb(obj.toString());
					
					dataSuppliersOrder.clear();
					DefaultTableModel model111 = (DefaultTableModel) table_8.getModel();
					model111.fireTableDataChanged();
					for(int i =0;i<arrs.size();i+=4)
					{
						Vector<String> rowso = new Vector<String>();
						rowso.add(arrs.get(i)); 
						rowso.add(arrs.get(i+1));
						rowso.add(arrs.get(i+2));
						rowso.add(arrs.get(i+3));
						dataSuppliersOrder.add(rowso);
						
						
						
					}
					
					System.out.println(dataSuppliersOrder);
					DefaultTableModel model11 = (DefaultTableModel) table_8.getModel();
					model11.fireTableDataChanged();
					lblOrderStatus.setVisible(true);
					btnUpdateStatus.setVisible(true);
					statusbox.setVisible(true);
					lblNewLabel.setVisible(false);
					supnamebox.setVisible(false);
					lblNewLabel_1.setVisible(false);
					itemsBox.setVisible(false);
					lblQuantity_1.setVisible(false);
					lblQuantity_1.setVisible(false);
					btnCloseOrder.setVisible(false);
					btnAddToOrder.setVisible(false);
					btnDeleteFromOrder.setVisible(false);
					lblNewLabel_4.setVisible(false);
					orderSum.setVisible(false);
					lblPricePerUnit.setVisible(false);
					textField_PriceUnit.setVisible(false);
					Quantity.setVisible(false);
					
					orderframe.setVisible(true);
				}
				else
				{
					JOptionPane.showMessageDialog(null, "Please A Row ");	
				    orderframe.setVisible(false);
				}
			
			}
			
		});
		watchorderopen.setFont(new Font("Tahoma", Font.PLAIN, 14));
		watchorderopen.setBounds(461, 361, 117, 33);
		orderpanel.add(watchorderopen);
		
		
		JPanel panel_1 = new JPanel();
		if(i==1)
		tabbedPane.addTab("New order", null, panel_1, null);
		panel_1.setLayout(null);
		
	    Label label = new Label("Supplier");
		label.setFont(new Font("Tahoma", Font.PLAIN, 15));
		label.setBounds(257, 76, 61, 19);
		panel_1.add(label);
		
		JLabel label_1 = new JLabel("Order details");
		label_1.setBounds(376, 33, 91, 20);
		label_1.setFont(new Font("Tahoma", Font.PLAIN, 16));
		panel_1.add(label_1);
		
		JComboBox comboBox = new JComboBox();
		comboBox.setBounds(336, 76, 191, 20);
		panel_1.add(comboBox);
		
		JLabel lblNewLabel_2 = new JLabel("Item");
		lblNewLabel_2.setFont(new Font("Tahoma", Font.PLAIN, 15));
		lblNewLabel_2.setBounds(257, 130, 46, 14);
		panel_1.add(lblNewLabel_2);
		
		JLabel lblQuantity = new JLabel("Quantity");
		lblQuantity.setFont(new Font("Tahoma", Font.PLAIN, 15));
		lblQuantity.setBounds(257, 167, 61, 19);
		panel_1.add(lblQuantity);
		
		JLabel lblNewLabel_3 = new JLabel("Price");
		lblNewLabel_3.setFont(new Font("Tahoma", Font.PLAIN, 15));
		lblNewLabel_3.setBounds(257, 204, 46, 14);
		panel_1.add(lblNewLabel_3);
		
		textField_1 = new JTextField();
		textField_1.setBounds(336, 129, 190, 20);
		panel_1.add(textField_1);
		textField_1.setColumns(10);
		
		textField_2 = new JTextField();
		textField_2.setBounds(337, 166, 190, 20);
		panel_1.add(textField_2);
		textField_2.setColumns(10);
		
		textField_3 = new JTextField();
		textField_3.setBounds(337, 198, 190, 20);
		panel_1.add(textField_3);
		textField_3.setColumns(10);
		
		table_1 = new JTable();
		table_1.setBorder(new LineBorder(new Color(0, 0, 0), 2));
		table_1.setModel(new DefaultTableModel(
			new Object[][] {
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
				{null, null, null, null},
			},
			new String[] {
				"Item", "ID", "Quantity", "Price"
			}
		));
		table_1.setBounds(161, 310, 553, 96);
		panel_1.add(table_1);
		
		JButton btnCompleteOrder = new JButton("Complete order");
		btnCompleteOrder.setFont(new Font("Tahoma", Font.PLAIN, 18));
		btnCompleteOrder.setBounds(299, 417, 268, 54);
		panel_1.add(btnCompleteOrder);
		
		JButton btnAddItemsTo = new JButton("Add items to order");
		btnAddItemsTo.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnAddItemsTo.setBounds(347, 237, 160, 39);
		panel_1.add(btnAddItemsTo);
		
		JPanel panel_2 = new JPanel();
		tabbedPane.addTab("Customers Orders", null, panel_2, null);
		panel_2.setLayout(null);
		
		final JInternalFrame internalFrameCusOrder = new JInternalFrame("Add Customer Order",true,true,true,true);
		internalFrameCusOrder.setBounds(27, 11, 685, 385);
		panel_2.add(internalFrameCusOrder);
		internalFrameCusOrder.getContentPane().setLayout(null);
		
		JScrollPane scrollPane_7 = new JScrollPane();
		scrollPane_7.setBounds(255, 11, 404, 237);
		internalFrameCusOrder.getContentPane().add(scrollPane_7);
	
		headersCusOrdersTO.add("Customer name");
		headersCusOrdersTO.add("Item name");
		headersCusOrdersTO.add("Quantity");
		headersCusOrdersTO.add("Price");
		
		templeCusOrder = new JTable(dataCustomersOrder,headersCusOrdersTO)
		{
			private static final long serialVersionUID = 1L;
			public boolean isCellEditable(int data, int columns)
            {
                if(columns>=1)
         	     return false;
                else return true;
            }
		};
		
		scrollPane_7.setViewportView(templeCusOrder);
		
		final JComboBox<String> cusnamebox = new JComboBox<String>();
		cusnamebox.setBounds(119, 49, 114, 22);
		
		ArrayList<String> arrCNL=new ArrayList<String>();
		Customers combocus =new  Customers();
		arrCNL=combocus.getCustomersNamesList();
		for(int i=0;i<arrCNL.size();i++)
		cusnamebox.addItem(arrCNL.get(i));
		internalFrameCusOrder.getContentPane().add(cusnamebox);
		
		final JComboBox<String> itemsBoxCus = new JComboBox<String>();
		itemsBoxCus.setBounds(119, 91, 114, 22);
		for(int i=0;i<arrIL.size();i+=2)
		itemsBoxCus.addItem(arrIL.get(i)+"-"+arrIL.get(i+1));
		internalFrameCusOrder.getContentPane().add(itemsBoxCus);
		
		final JLabel lblCustomer = new JLabel("Customer :");
		lblCustomer.setBounds(10, 51, 73, 14);
		lblCustomer.setFont(new Font("Tahoma", Font.PLAIN, 14));
		internalFrameCusOrder.getContentPane().add(lblCustomer);
		
		final JLabel lblItem = new JLabel("Item :");
		lblItem.setBounds(10, 93, 73, 14);
		lblItem.setFont(new Font("Tahoma", Font.PLAIN, 14));
		internalFrameCusOrder.getContentPane().add(lblItem);
		
		final JLabel lblPricePerUnit_1 = new JLabel("Price per unit:");
		lblPricePerUnit_1.setBounds(10, 135, 99, 17);
		lblPricePerUnit_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
		internalFrameCusOrder.getContentPane().add(lblPricePerUnit_1);
		
		final JLabel lblQuantity_2 = new JLabel("Quantity:");
		lblQuantity_2.setBounds(10, 177, 99, 17);
		lblQuantity_2.setFont(new Font("Tahoma", Font.PLAIN, 14));
		internalFrameCusOrder.getContentPane().add(lblQuantity_2);
		
		textFieldPricePerUnitCus = new JTextField();
		textFieldPricePerUnitCus.setBounds(119, 135, 114, 20);
		textFieldPricePerUnitCus.setColumns(10);
		internalFrameCusOrder.getContentPane().add(textFieldPricePerUnitCus);
		
		textFieldQuantityCus = new JTextField();
		textFieldQuantityCus.setBounds(119, 177, 114, 20);
		textFieldQuantityCus.setColumns(10);
		internalFrameCusOrder.getContentPane().add(textFieldQuantityCus);
		
		final JLabel label_5 = new JLabel("Total sum:");
		label_5.setBounds(257, 278, 114, 14);
		label_5.setFont(new Font("Tahoma", Font.PLAIN, 14));
		internalFrameCusOrder.getContentPane().add(label_5);
		
		orderSumCus = new JTextField();
		orderSumCus.setBounds(332, 273, 114, 20);
		orderSumCus.setFont(new Font("Tahoma", Font.PLAIN, 14));
		orderSumCus.setColumns(10);
		internalFrameCusOrder.getContentPane().add(orderSumCus);
		
		final JButton button = new JButton("Add to order");
		button.setBounds(31, 215, 166, 33);
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if( isNumeric(textFieldQuantityCus.getText())&&isNumeric(textFieldPricePerUnitCus.getText()))
				{
				String cusName=(String) cusnamebox.getSelectedItem();
				String itemName =(String) itemsBoxCus.getSelectedItem();
				String quantityOfItems=textFieldQuantityCus.getText();
				String priceOfItem=textFieldPricePerUnitCus.getText();
				String AllPrice;
				int price=Integer.parseInt(quantityOfItems)*Integer.parseInt(priceOfItem);
				orderPriceCus+=price;
				AllPrice=Integer.toString(price);
				Vector<String> rowco2 = new Vector<String>();
				rowco2.add(cusName); 
				rowco2.add(itemName);
				rowco2.add(quantityOfItems);
				rowco2.add(AllPrice);
				dataCustomersOrder.add(rowco2);
				DefaultTableModel model112 = (DefaultTableModel) templeCusOrder.getModel();
				model112.fireTableDataChanged();
				orderSumCus.setText(String.valueOf(orderPriceCus));
				cusnamebox.disable();
				}
			else JOptionPane.showMessageDialog(null, "Please enter only digits");	
			}
		});
		button.setFont(new Font("Tahoma", Font.PLAIN, 14));
		internalFrameCusOrder.getContentPane().add(button);
		
		final JButton button_3 = new JButton("Delete items");
		button_3.setBounds(31, 259, 166, 33);
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(templeCusOrder.getSelectedRow()>=0)
				{
					Vector<String> tempvect2 = new Vector<String>();
					tempvect2=dataCustomersOrder.get(templeCusOrder.getSelectedRow());
					orderPriceCus-=Integer.parseInt(tempvect2.get(3));
					orderSumCus.setText(String.valueOf(orderPriceCus));
		        	dataCustomersOrder.remove(templeCusOrder.getSelectedRow());   
		        	DefaultTableModel model13 = (DefaultTableModel) templeCusOrder.getModel();
		        	model13.fireTableDataChanged();
				}
			}
		});
		button_3.setFont(new Font("Tahoma", Font.PLAIN, 14));
		internalFrameCusOrder.getContentPane().add(button_3);
		
		final JButton button_4 = new JButton("Complete Order");
		button_4.setBounds(498, 259, 136, 39);
		button_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			ArrayList<String> cusOrderAdd= new  ArrayList<String>();
			cusOrderAdd.add((String) cusnamebox.getSelectedItem());
			cusOrderAdd.add(Integer.toString(orderPriceCus));
			CustomerOrdersLog coadd = new CustomerOrdersLog();	
			coadd.openCusOrder(cusOrderAdd,dataCustomersOrder);	
			dataCustomersOrder.clear();
			internalFrameCusOrder.setVisible(false);
			updateCusOrdersTable();
			}
		});
		button_4.setFont(new Font("Tahoma", Font.PLAIN, 14));
		internalFrameCusOrder.getContentPane().add(button_4);
		
		final JLabel lblUpdateStatus = new JLabel("Update status");
		
		lblUpdateStatus.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblUpdateStatus.setBounds(10, 26, 99, 22);
		internalFrameCusOrder.getContentPane().add(lblUpdateStatus);
		
		final JComboBox<String> comboBox_2 = new JComboBox();
		comboBox_2.setFont(new Font("Tahoma", Font.PLAIN, 14));
		comboBox_2.setModel(new DefaultComboBoxModel(new String[] {"initialize", "shipped", "in wherehouse", "canceld", "closed"}));
		comboBox_2.setBounds(119, 29, 114, 20);
		internalFrameCusOrder.getContentPane().add(comboBox_2);
		
		final JButton btnUpdateStatus_1 = new JButton("Update Status");
		btnUpdateStatus_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			
			
				int x = table_cus_orders.getSelectedRow();
				if( x>-1)
				{
					ArrayList<String> arrs =new ArrayList<>();
					arrs.clear();
					Object obj = table_cus_orders.getModel().getValueAt(x, 0);
					CustomerOrdersLog c = new CustomerOrdersLog();
					if(c.updateorderstatuscust(obj.toString(), comboBox_2.getSelectedItem().toString())==1)
					{
						JOptionPane.showMessageDialog(null, "Status updated succsesfuly");	
						updateCusOrdersTable();
						internalFrameCusOrder.setVisible(false);
					}	
						else
							JOptionPane.showMessageDialog(null, "error while updating status");	
						
				}
			
			}
		});
		btnUpdateStatus_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnUpdateStatus_1.setBounds(31, 215, 166, 33);
		internalFrameCusOrder.getContentPane().add(btnUpdateStatus_1);
		internalFrameCusOrder.setVisible(false);
		
		JScrollPane scrollPane_6 = new JScrollPane();
		scrollPane_6.setBounds(27, 21, 699, 385);
		panel_2.add(scrollPane_6);
		headersCusOrders.add("Order ID");
		headersCusOrders.add("Supplier name");
		headersCusOrders.add("Start date");
		headersCusOrders.add("End date");
		headersCusOrders.add("Price");
		headersCusOrders.add("Status");
		CustomerOrdersLog cusO = new CustomerOrdersLog();
		ArrayList<String> rescus= cusO.getCustomersOrders();
		for (int i=0; i<=(rescus.size())-6;i=i+6)
		{
			Vector<String> rowso = new Vector<String>();
				rowso.add(rescus.get(i)); 
				rowso.add(rescus.get(i+1));
				rowso.add(rescus.get(i+2));
				rowso.add(rescus.get(i+3));
				rowso.add(rescus.get(i+4));
				rowso.add(rescus.get(i+5));
				dataCusOrders.add(rowso);

			
		}
		table_cus_orders  = new JTable(dataCusOrders,headersCusOrders)
		{
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			public boolean isCellEditable(int data, int columns)
            {
                if(columns>=1)
         	     return false;
                else return true;
            }
		};
		
		scrollPane_6.setViewportView(table_cus_orders);
		
		JButton btnAddOrder = new JButton("Add Order");
		btnAddOrder.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lblUpdateStatus.setVisible(false);
				lblCustomer.setVisible(true);
				btnUpdateStatus_1.setVisible(false);
				comboBox_2.setVisible(false);
				lblItem.setVisible(true);
				lblPricePerUnit_1.setVisible(true);
				lblQuantity_2.setVisible(true);
				cusnamebox.setVisible(true);
				itemsBoxCus.setVisible(true);
				textFieldPricePerUnitCus.setVisible(true);
				button.setVisible(true);
				button_3.setVisible(true);
				button_4.setVisible(true);
				textFieldQuantityCus.setVisible(true);
				label_5.setVisible(true);
				orderSumCus.setVisible(true);
				cusnamebox.enable();
				orderPriceCus=0;
				orderSumCus.setText("");
				dataCustomersOrder.clear();
				textFieldQuantityCus.setText("");
				textFieldPricePerUnitCus.setText("");	
				internalFrameCusOrder.setVisible(true);
				
			}
		});
		btnAddOrder.setBounds(165, 407, 117, 38);
		btnAddOrder.setFont(new Font("Tahoma", Font.PLAIN, 14));
		panel_2.add(btnAddOrder);
		
		JButton btnWatchOrder = new JButton("Watch Order");
		btnWatchOrder.setBounds(459, 407, 117, 38);
		btnWatchOrder.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				int x = table_cus_orders.getSelectedRow();
				if( x>-1)
				{
					ArrayList<String> arrs =new ArrayList<>();
					arrs.clear();
					Object obj = table_cus_orders.getModel().getValueAt(x, 0);
					CustomerOrdersLog so = new CustomerOrdersLog();
					arrs=so.getorderfromdb(obj.toString());
					dataCustomersOrder.clear();
					DefaultTableModel model111 = (DefaultTableModel) templeCusOrder.getModel();
					model111.fireTableDataChanged();
					for(int i =0;i<arrs.size();i+=4)
					{
						Vector<String> rowso = new Vector<String>();
						rowso.add(arrs.get(i)); 
						rowso.add(arrs.get(i+1));
						rowso.add(arrs.get(i+2));
						rowso.add(arrs.get(i+3));
						dataCustomersOrder.add(rowso);
					}
					
					System.out.println(dataCustomersOrder);
					DefaultTableModel model11 = (DefaultTableModel) templeCusOrder.getModel();
					model11.fireTableDataChanged();
					lblUpdateStatus.setVisible(true);
					btnUpdateStatus_1.setVisible(true);
					comboBox_2.setVisible(true);
					lblCustomer.setVisible(false);
					lblItem.setVisible(false);
					lblPricePerUnit_1.setVisible(false);
					lblQuantity_2.setVisible(false);
					cusnamebox.setVisible(false);
					itemsBoxCus.setVisible(false);
					textFieldPricePerUnitCus.setVisible(false);
					button.setVisible(false);
					button_3.setVisible(false);
					button_4.setVisible(false);
					textFieldQuantityCus.setVisible(false);
					label_5.setVisible(false);
					orderSumCus.setVisible(false);
					
					
					
					
				
					internalFrameCusOrder.setVisible(true);
				}
				else
				{
					JOptionPane.showMessageDialog(null, "Please A Row ");	
				    orderframe.setVisible(false);
				}
			
			}
		});
		btnWatchOrder.setFont(new Font("Tahoma", Font.PLAIN, 14));
		panel_2.add(btnWatchOrder);
	
		
		
		JPanel panel_3 = new JPanel();
		tabbedPane.addTab("Suppliers", null, panel_3, null);
		panel_3.setLayout(null);
		headersSup.add("Supplier ID");
		headersSup.add("Name");
		headersSup.add("Country");
		headersSup.add("City");
		headersSup.add("Address");
		headersSup.add("Tel");
		headersSup.add("Fax");
		headersSup.add("Email");
		headersSup.add("Account");
		
	Suppliers sup = new Suppliers();
	ArrayList<String> ress= sup.getSuppliers();
	for (int i=0; i<=(ress.size())-9;i=i+9)
	{
		Vector<String> rows = new Vector<String>();
			rows.add(ress.get(i)); 
			rows.add(ress.get(i+1));
			rows.add(ress.get(i+2));
			rows.add(ress.get(i+3));
			rows.add(ress.get(i+4));
			rows.add(ress.get(i+5));
			rows.add(ress.get(i+6));
			rows.add(ress.get(i+7));
			rows.add(ress.get(i+8));
		dataSuppliers.add(rows);
	}
		
	final JInternalFrame internalFrameSup = new JInternalFrame("New JInternalFrame",true,true,true,true);
	internalFrameSup.setForeground(Color.MAGENTA);
	//internalFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
	internalFrameSup.getContentPane().setBackground(Color.GRAY);
	internalFrameSup.setBounds(0, 0, 257, 378);
	internalFrameSup.setVisible(false);
	panel_3.add(internalFrameSup);
	internalFrameSup.getContentPane().setLayout(null);
	
	JLabel lblSupplierId = new JLabel("Supplier ID");
	lblSupplierId.setFont(new Font("Tahoma", Font.PLAIN, 14));
	lblSupplierId.setBounds(20, 47, 83, 14);
	internalFrameSup.getContentPane().add(lblSupplierId);
	
	JLabel lblName_1 = new JLabel("Name");
	lblName_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
	lblName_1.setBounds(20, 72, 46, 14);
	internalFrameSup.getContentPane().add(lblName_1);
	
	JLabel lblCountry = new JLabel("Country");
	lblCountry.setFont(new Font("Tahoma", Font.PLAIN, 14));
	lblCountry.setBounds(20, 92, 70, 25);
	internalFrameSup.getContentPane().add(lblCountry);
	
	JLabel lblCity = new JLabel("City");
	lblCity.setFont(new Font("Tahoma", Font.PLAIN, 14));
	lblCity.setBounds(20, 119, 46, 25);
	internalFrameSup.getContentPane().add(lblCity);
	
	JLabel lblAddress_1 = new JLabel("Address");
	lblAddress_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
	lblAddress_1.setBounds(20, 149, 70, 14);
	internalFrameSup.getContentPane().add(lblAddress_1);
	
	JLabel lblTelephone_1 = new JLabel("Telephone");
	lblTelephone_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
	lblTelephone_1.setBounds(20, 174, 70, 14);
	internalFrameSup.getContentPane().add(lblTelephone_1);
	
	JLabel lblFax = new JLabel("Fax");
	lblFax.setFont(new Font("Tahoma", Font.PLAIN, 14));
	lblFax.setBounds(20, 199, 46, 14);
	internalFrameSup.getContentPane().add(lblFax);
	
	JLabel lblEmail_1 = new JLabel("Email");
	lblEmail_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
	lblEmail_1.setBounds(20, 227, 46, 14);
	internalFrameSup.getContentPane().add(lblEmail_1);
	
	JLabel lblAccount = new JLabel("Account");
	lblAccount.setFont(new Font("Tahoma", Font.PLAIN, 14));
	lblAccount.setBounds(20, 252, 70, 14);
	internalFrameSup.getContentPane().add(lblAccount);
	
	textField_4 = new JTextField();
	textField_4.setBounds(107, 46, 124, 20);
	internalFrameSup.getContentPane().add(textField_4);
	textField_4.setColumns(10);
	
	textField_5 = new JTextField();
	textField_5.setColumns(10);
	textField_5.setBounds(107, 71, 124, 20);
	internalFrameSup.getContentPane().add(textField_5);
	
	textField_6 = new JTextField();
	textField_6.setColumns(10);
	textField_6.setBounds(107, 96, 124, 20);
	internalFrameSup.getContentPane().add(textField_6);
	
	textField_7 = new JTextField();
	textField_7.setColumns(10);
	textField_7.setBounds(107, 123, 124, 20);
	internalFrameSup.getContentPane().add(textField_7);
	
	textField_8 = new JTextField();
	textField_8.setColumns(10);
	textField_8.setBounds(107, 148, 124, 20);
	internalFrameSup.getContentPane().add(textField_8);
	
	textField_9 = new JTextField();
	textField_9.setColumns(10);
	textField_9.setBounds(107, 173, 124, 20);
	internalFrameSup.getContentPane().add(textField_9);
	
	textField_10 = new JTextField();
	textField_10.setColumns(10);
	textField_10.setBounds(107, 198, 124, 20);
	internalFrameSup.getContentPane().add(textField_10);
	
	textField_11 = new JTextField();
	textField_11.setColumns(10);
	textField_11.setBounds(107, 226, 124, 20);
	internalFrameSup.getContentPane().add(textField_11);
	
	textField_12 = new JTextField();
	textField_12.setColumns(10);
	textField_12.setBounds(107, 251, 124, 20);
	internalFrameSup.getContentPane().add(textField_12);
	
	final JComboBox<String> comboBoxSupnames = new JComboBox();
	updateSupCombo(comboBoxSupnames);
	comboBoxSupnames.setBounds(105, 129, 121, 20);
	final JInternalFrame itemframe = new JInternalFrame("New JInternalFrame",true,true,true,true);
	itemframe.getContentPane().add(comboBoxSupnames);
	
	
	final JButton btnAddSupplier_1 = new JButton("Add Supplier");
	btnAddSupplier_1.setBounds(63, 286, 116, 41);
	internalFrameSup.getContentPane().add(btnAddSupplier_1);
	btnAddSupplier_1.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent arg0) {
    				String names=textField_5.getText();
    				String country =textField_6.getText();
    				String city=textField_7.getText();
    				String addresss=textField_8.getText();
    				String tels=textField_9.getText();
    				String faxs=textField_10.getText();
    				String email=textField_11.getText();
    				String accaount=textField_12.getText();
    				ArrayList<String> suparr= new  ArrayList<String>();
    				suparr.add(names);suparr.add(country);suparr.add(city);suparr.add(addresss);suparr.add(tels);suparr.add(faxs);suparr.add(email);suparr.add(accaount);
    				Suppliers supadd = new Suppliers();
    				supadd.adduser(suparr);
    				internalFrameSup.setVisible(false);
    				updateSupllierTable();
    				updateSupCombo(supnamebox);
    				updateSupCombo(comboBoxSupnames);
		}
	});
	btnAddSupplier_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
	
	final JButton btnUpdate_1 = new JButton("Update");
	btnUpdate_1.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent arg0) {
			int y = table_4.getSelectedColumn();
			int x = table_4.getSelectedRow();
			if(y<1)
			{
				ArrayList<String> arrs =new ArrayList<>();
				arrs.clear();
				Object obj = table_4.getModel().getValueAt(x, y);
				arrs.add(textField_5.getText());
				arrs.add(textField_6.getText());
				arrs.add(textField_7.getText());
				arrs.add(textField_8.getText());
				arrs.add(textField_9.getText());
				arrs.add(textField_10.getText());
				arrs.add(textField_11.getText());
				arrs.add(textField_12.getText());
				arrs.add(obj.toString());
		
			Suppliers s = new Suppliers();
			if(s.updateSuppliersDetails(arrs)==1)
				{
					
				JOptionPane.showMessageDialog(null, "User Updated Successfully");
				internalFrameSup.setVisible(false);
				updateSupllierTable();
				
				}
			else
				JOptionPane.showMessageDialog(null, "Error Update User");	
			
			
			}
			updateSupCombo(supnamebox);
			updateSupCombo(comboBoxSupnames);
		}
	});
	btnUpdate_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
	btnUpdate_1.setBounds(63, 286, 116, 41);
	internalFrameSup.getContentPane().add(btnUpdate_1);
		
		JScrollPane scrollPane_1 = new JScrollPane();
		scrollPane_1.setBounds(23, 22, 812, 307);
		panel_3.add(scrollPane_1);
		table_4 = new JTable(dataSuppliers,headersSup)
		{
         
			private static final long serialVersionUID = 1L;

			public boolean isCellEditable(int data, int columns)
            {
                if(columns>=1)
         	     return false;
                else return true;
            }
     };
		table_4.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				ArrayList<String> sd =new ArrayList<>();
				
				int x = table_4.getSelectedRow();
				if(x > -1)
				{
				Object obj = table_4.getModel().getValueAt(x,0);
				Suppliers ss = new Suppliers();
				sd=ss.getSupplierDetails(obj.toString());
				textField_4.setText(sd.get(0));
				textField_5.setText(sd.get(1));
				textField_6.setText(sd.get(2));
				textField_7.setText(sd.get(3));
				textField_8.setText(sd.get(4));
				textField_9.setText(sd.get(5));
				textField_10.setText(sd.get(6));
				textField_11.setText(sd.get(7));
				textField_12.setText(sd.get(8));
				}
				
			}
		});
		
      
            scrollPane_1.setViewportView(table_4);
            
            JButton btnAddSupplier = new JButton("Add Supplier");
            btnAddSupplier.addActionListener(new ActionListener() {
            	public void actionPerformed(ActionEvent e) {
            		 
            		textField_4.setText("");
            		textField_4.disable();
    				textField_5.setText("");
    				textField_6.setText("");
    				textField_7.setText("");
    				textField_8.setText("");
    				textField_9.setText("");
    				textField_10.setText("");
    				textField_11.setText("");
    				textField_12.setText("");
    				btnUpdate_1.setVisible(false);
    				btnAddSupplier_1.setVisible(true);
    				internalFrameSup.setVisible(true);
    				
    				
            	}
            });
            btnAddSupplier.setBounds(298, 373, 117, 38);
            panel_3.add(btnAddSupplier);
            btnAddSupplier.setFont(new Font("Tahoma", Font.PLAIN, 14));
            
            JButton btnDeleteSupplier = new JButton("Delete Supplier");
            btnDeleteSupplier.addActionListener(new ActionListener() {
            	public void actionPerformed(ActionEvent arg0) {
            		
    				int x = table_4.getSelectedRow();
    				if( x >-1)
    				{
    				Object obj = table_4.getModel().getValueAt(x, 0);
    				System.out.print(obj.toString());
    				Suppliers s = new  Suppliers();
    				if(s.deleteSupplier(obj.toString())==1)
    					{
    						
    					JOptionPane.showMessageDialog(null, "User Deleted Successfully");
    					updateSupllierTable();
    					updateSupCombo(supnamebox);
        				updateSupCombo(comboBoxSupnames);
    					}
    				else
    					JOptionPane.showMessageDialog(null, "Error Deleting User");	
    				}
    				else
    					JOptionPane.showMessageDialog(null, "Please Select Only User Name");	
            		}
            	
            });
            btnDeleteSupplier.setFont(new Font("Tahoma", Font.PLAIN, 14));
            btnDeleteSupplier.setBackground(new Color(204, 51, 255));
            btnDeleteSupplier.setBounds(575, 373, 149, 38);
            panel_3.add(btnDeleteSupplier);
            
            JButton button_1 = new JButton("Update Detalis");
            button_1.addActionListener(new ActionListener() {
            	public void actionPerformed(ActionEvent arg0) {
            		textField_4.disable();
            		btnUpdate_1.setVisible(true);
            		btnAddSupplier_1.setVisible(false);
    				internalFrameSup.setVisible(true);		
            	}
            });
            button_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
            button_1.setBounds(434, 372, 121, 41);
            panel_3.add(button_1);
		
		JPanel panel_4 = new JPanel();
		tabbedPane.addTab("Customers", null, panel_4, null);
		panel_4.setLayout(null);
		
		
		final JInternalFrame internalFrameCus = new JInternalFrame("New JInternalFrame",true,true,true,true);
		internalFrameCus.setForeground(Color.MAGENTA);
		//internalFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
     internalFrameCus.getContentPane().setBackground(Color.GRAY);
     internalFrameCus.setBounds(0, 0, 257, 378);
     internalFrameCus.setVisible(false);
     panel_4.add(internalFrameCus);
     internalFrameCus.getContentPane().setLayout(null);
     
     JLabel lblCustomerId = new JLabel("Customer ID");
     lblCustomerId.setFont(new Font("Tahoma", Font.PLAIN, 14));
     lblCustomerId.setBounds(20, 47, 83, 14);
     internalFrameCus.getContentPane().add(lblCustomerId);
     
     JLabel lblName_11 = new JLabel("Name");
     lblName_11.setFont(new Font("Tahoma", Font.PLAIN, 14));
     lblName_11.setBounds(20, 72, 46, 14);
     internalFrameCus.getContentPane().add(lblName_11);
     
     JLabel lblCountry1 = new JLabel("Country");
     lblCountry1.setFont(new Font("Tahoma", Font.PLAIN, 14));
     lblCountry1.setBounds(20, 92, 70, 25);
     internalFrameCus.getContentPane().add(lblCountry1);
     
     JLabel lblCity1 = new JLabel("City");
     lblCity1.setFont(new Font("Tahoma", Font.PLAIN, 14));
     lblCity1.setBounds(20, 119, 46, 25);
     internalFrameCus.getContentPane().add(lblCity1);
     
     JLabel lblAddress_11 = new JLabel("Address");
     lblAddress_11.setFont(new Font("Tahoma", Font.PLAIN, 14));
     lblAddress_11.setBounds(20, 149, 70, 14);
     internalFrameCus.getContentPane().add(lblAddress_11);
     
     JLabel lblTelephone_11 = new JLabel("Telephone");
     lblTelephone_11.setFont(new Font("Tahoma", Font.PLAIN, 14));
     lblTelephone_11.setBounds(20, 174, 70, 14);
     internalFrameCus.getContentPane().add(lblTelephone_11);
     
     JLabel lblFax1 = new JLabel("Fax");
     lblFax1.setFont(new Font("Tahoma", Font.PLAIN, 14));
     lblFax1.setBounds(20, 199, 46, 14);
     internalFrameCus.getContentPane().add(lblFax1);
     
     JLabel lblEmail_11 = new JLabel("Email");
     lblEmail_11.setFont(new Font("Tahoma", Font.PLAIN, 14));
     lblEmail_11.setBounds(20, 227, 46, 14);
     internalFrameCus.getContentPane().add(lblEmail_11);
     
     JLabel lblAccount1 = new JLabel("Account");
     lblAccount1.setFont(new Font("Tahoma", Font.PLAIN, 14));
     lblAccount1.setBounds(20, 252, 70, 14);
     internalFrameCus.getContentPane().add(lblAccount1);
     
     textField_41 = new JTextField();
     textField_41.setBounds(107, 46, 124, 20);
     internalFrameCus.getContentPane().add(textField_41);
     textField_41.setColumns(10);
     
     textField_51 = new JTextField();
     textField_51.setColumns(10);
     textField_51.setBounds(107, 71, 124, 20);
     internalFrameCus.getContentPane().add(textField_51);
     
     textField_61 = new JTextField();
     textField_61.setColumns(10);
     textField_61.setBounds(107, 96, 124, 20);
     internalFrameCus.getContentPane().add(textField_61);
     
     textField_71 = new JTextField();
     textField_71.setColumns(10);
     textField_71.setBounds(107, 123, 124, 20);
     internalFrameCus.getContentPane().add(textField_71);
     
     textField_81 = new JTextField();
     textField_81.setColumns(10);
     textField_81.setBounds(107, 148, 124, 20);
     internalFrameCus.getContentPane().add(textField_81);
     
     textField_91 = new JTextField();
     textField_91.setColumns(10);
     textField_91.setBounds(107, 173, 124, 20);
     internalFrameCus.getContentPane().add(textField_91);
     
     textField_101 = new JTextField();
     textField_101.setColumns(10);
     textField_101.setBounds(107, 198, 124, 20);
     internalFrameCus.getContentPane().add(textField_101);
     
     textField_111 = new JTextField();
     textField_111.setColumns(10);
     textField_111.setBounds(107, 226, 124, 20);
     internalFrameCus.getContentPane().add(textField_111);
     
     textField_121 = new JTextField();
     textField_121.setColumns(10);
     textField_121.setBounds(107, 251, 124, 20);
     internalFrameCus.getContentPane().add(textField_121);
     
     final JButton btnAddCustomer = new JButton("Add Customer");
     btnAddCustomer.addActionListener(new ActionListener() {
     	public void actionPerformed(ActionEvent e) {
     		String names=textField_51.getText();
			String country =textField_61.getText();
			String city=textField_71.getText();
			String addresss=textField_81.getText();
			String tels=textField_91.getText();
			String faxs=textField_101.getText();
			String email=textField_111.getText();
			String accaount=textField_121.getText();
			ArrayList<String> cusarr= new  ArrayList<String>();
			cusarr.add(names);cusarr.add(country);cusarr.add(city);cusarr.add(addresss);cusarr.add(tels);cusarr.add(faxs);cusarr.add(email);cusarr.add(accaount);
			Customers cusadd = new Customers();
			cusadd.adduser(cusarr);
			internalFrameCus.setVisible(false);
			try {
				updateCustomerTable();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
     	}
     });
     btnAddCustomer.setFont(new Font("Tahoma", Font.PLAIN, 14));
     btnAddCustomer.setBounds(66, 286, 135, 41);
     internalFrameCus.getContentPane().add(btnAddCustomer);
     
     final JButton btnUpdate_2 = new JButton("Update");
     btnUpdate_2.addActionListener(new ActionListener() {
     	public void actionPerformed(ActionEvent e) {
     		
			int x = table_Customers.getSelectedRow();
			if(x >-1)
			{
				ArrayList<String> arrs =new ArrayList<>();
				arrs.clear();
				Object obj = table_Customers.getModel().getValueAt(x, 0);
				arrs.add(textField_51.getText());
				arrs.add(textField_61.getText());
				arrs.add(textField_71.getText());
				arrs.add(textField_81.getText());
				arrs.add(textField_91.getText());
				arrs.add(textField_101.getText());
				arrs.add(textField_111.getText());
				arrs.add(textField_121.getText());
				arrs.add(obj.toString());
		
			Customers s = new Customers();
			if(s.updateCustomersDetails(arrs)==1)
				{
					
				JOptionPane.showMessageDialog(null, "Customer Updated Successfully");
				internalFrameCus.setVisible(false);
				try {
					updateCustomerTable();
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				}
			else
				JOptionPane.showMessageDialog(null, "Error Update User");	
			
			
			}
     	}
     });
     btnUpdate_2.setFont(new Font("Tahoma", Font.PLAIN, 14));
     btnUpdate_2.setBounds(66, 286, 116, 41);
     internalFrameCus.getContentPane().add(btnUpdate_2);
		
		JScrollPane scrollPane_Customers = new JScrollPane();
		scrollPane_Customers.setBounds(27, 24, 732, 233);
		panel_4.add(scrollPane_Customers);
		
		headersCus.add("Customer ID");
		headersCus.add("Name");
		headersCus.add("Country");
		headersCus.add("City");
		headersCus.add("Address");
		headersCus.add("Tel");
		headersCus.add("Fax");
		headersCus.add("Email");
		headersCus.add("Account");
		Customers  cus = new Customers();
	
		ArrayList<String> resc= cus.getCustomers();
		for (int i=0; i<=(resc.size())-9;i=i+9)
		{
			Vector<String> rows = new Vector<String>();
				rows.add(resc.get(i)); 
				rows.add(resc.get(i+1));
				rows.add(resc.get(i+2));
				rows.add(resc.get(i+3));
				rows.add(resc.get(i+4));
				rows.add(resc.get(i+5));
				rows.add(resc.get(i+6));
				rows.add(resc.get(i+7));
				rows.add(resc.get(i+8));
				dataCustomers.add(rows);
		}
		
		table_Customers  = new JTable(dataCustomers,headersCus)
		{
            /**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			public boolean isCellEditable(int data, int columns)
            {
                if(columns>=1)
         	     return false;
                else return true;
            }
     };
     
     
		table_Customers.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				ArrayList<String> sd1 =new ArrayList<>();
				
				int x = table_Customers.getSelectedRow();
				if(x >-1)
				{
				Object obj = table_Customers.getModel().getValueAt(x,0);
				Customers ss = new Customers();
				sd1=ss.getCustomersDetails(obj.toString());
				textField_41.setText(sd1.get(0));
				textField_51.setText(sd1.get(1));
				textField_61.setText(sd1.get(2));
				textField_71.setText(sd1.get(3));
				textField_81.setText(sd1.get(4));
				textField_91.setText(sd1.get(5));
				textField_101.setText(sd1.get(6));
				textField_111.setText(sd1.get(7));
				textField_121.setText(sd1.get(8));
				}
				
			}
		});
		
		
		scrollPane_Customers.setViewportView(table_Customers);
		
		JButton btnAddCustomer_1 = new JButton("Add Customer");
		btnAddCustomer_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

       		 
        		textField_41.setText("");
        		textField_41.disable();
				textField_51.setText("");
				textField_61.setText("");
				textField_71.setText("");
				textField_81.setText("");
				textField_91.setText("");
				textField_101.setText("");
				textField_111.setText("");
				textField_121.setText("");
				btnUpdate_2.setVisible(false);
				btnAddCustomer.setVisible(true);
				internalFrameCus.setVisible(true);
			}
		});
		btnAddCustomer_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnAddCustomer_1.setBounds(252, 330, 139, 38);
		panel_4.add(btnAddCustomer_1);
		
		JButton button_2 = new JButton("Update Detalis");
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				textField_41.disable();
        		btnUpdate_2.setVisible(true);
        		btnAddCustomer.setVisible(false);
        		internalFrameCus.setVisible(true);	
			}
		});
		button_2.setFont(new Font("Tahoma", Font.PLAIN, 14));
		button_2.setBounds(414, 329, 121, 41);
		panel_4.add(button_2);
		
		JButton btnDeleteCustomer = new JButton("Delete Customer");
		btnDeleteCustomer.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				int x = table_Customers.getSelectedRow();
				if(x >-1)
				{
				Object obj = table_Customers.getModel().getValueAt(x,0);
				System.out.print(obj.toString());
				Customers s = new  Customers();
				if(s.deleteCustomer(obj.toString())==1)
					{
					JOptionPane.showMessageDialog(null, "Customer Deleted Successfully");
					try {
						updateCustomerTable();
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					}
				else
					JOptionPane.showMessageDialog(null, "Error Deleting User");	
				}
				else
					JOptionPane.showMessageDialog(null, "Please Select Only User Name");	
			}
		});
		btnDeleteCustomer.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnDeleteCustomer.setBackground(new Color(204, 51, 255));
		btnDeleteCustomer.setBounds(573, 330, 149, 38);
		panel_4.add(btnDeleteCustomer);
		
		JPanel inventorypanel = new JPanel();
		tabbedPane.addTab("Inventory", null, inventorypanel, null);
		inventorypanel.setLayout(null);
		
		final JInternalFrame inventoryframe = new JInternalFrame("New JInternalFrame",true,true,true,true);
		inventoryframe.setBounds(22, 23, 538, 127);
		inventorypanel.add(inventoryframe);
		inventoryframe.getContentPane().setLayout(null);
		
		JLabel lblShelfNumber = new JLabel("Shelf Number");
		lblShelfNumber.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblShelfNumber.setBounds(39, 27, 104, 20);
		inventoryframe.getContentPane().add(lblShelfNumber);
		
		txtshelf = new JTextField();
		txtshelf.setBounds(167, 29, 118, 20);
		inventoryframe.getContentPane().add(txtshelf);
		txtshelf.setColumns(10);
		
		JButton updateonshelf = new JButton("Update");
		updateonshelf.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				int x = inventory_table.getSelectedRow();
				if(x > -1)
				{
					
					ArrayList<String> ar = new ArrayList<String>();
					inventoryframe.setVisible(false);
					
					
					Object obj = inventory_table.getModel().getValueAt(x, 0);
					ar.add(obj.toString());
					ar.add(txtshelf.getText());
					System.out.print(ar);
					Items it = new Items();
					try
					{
						if(it.putonshelf(ar)==1)
						{
							JOptionPane.showMessageDialog(null, "shelf Updated Successfully");
							updateinventorytable();
						}
							else 
							JOptionPane.showMessageDialog(null, "Error Eccured");
					} 
					catch (SQLException e1) 
					{
						
						e1.printStackTrace();
					}
				
				}
				
			}
		});
		updateonshelf.setFont(new Font("Tahoma", Font.PLAIN, 14));
		updateonshelf.setBounds(351, 28, 95, 31);
		inventoryframe.getContentPane().add(updateonshelf);
		inventoryframe.setVisible(true);
		
		JScrollPane scrollPane_4 = new JScrollPane();
		scrollPane_4.setBounds(49, 37, 544, 353);
		inventorypanel.add(scrollPane_4);
		inventoryframe.setVisible(false);
		inventory_table = new JTable(inventory,headersinventory);
	
		scrollPane_4.setViewportView(inventory_table);
		inventory_table.setAutoCreateRowSorter(true);
		
		JButton shelfopen = new JButton("Put On Shelf");
		shelfopen.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				int x = inventory_table.getSelectedRow();
				if(x > -1)
				{
					
					inventoryframe.setVisible(true);
					
				
				}
				else
					JOptionPane.showMessageDialog(null, "Please Select Only Id");
				
			}
		});
		shelfopen.setFont(new Font("Tahoma", Font.PLAIN, 14));
		shelfopen.setBounds(49, 421, 133, 25);
		inventorypanel.add(shelfopen);
		JPanel panel_6 = new JPanel();
		tabbedPane.addTab("Users", null, panel_6, null);
		panel_6.setLayout(null);
		final JInternalFrame internalFrame = new JInternalFrame("New JInternalFrame",true,true,true,true);
		internalFrame.setForeground(Color.MAGENTA);
		//internalFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
		internalFrame.getContentPane().setBackground(Color.GRAY);
		internalFrame.setBounds(0, 0, 257, 378);
		internalFrame.setVisible(false);
		panel_6.add(internalFrame);
		internalFrame.getContentPane().setLayout(null);
		
		JLabel lblUsername = new JLabel("Username");
		lblUsername.setBounds(10, 42, 61, 17);
		internalFrame.getContentPane().add(lblUsername);
		lblUsername.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		username = new JTextField();
		username.setBounds(106, 42, 86, 20);
		internalFrame.getContentPane().add(username);
		username.setColumns(10);
		
		address = new JTextField();
		address.setBounds(106, 241, 86, 20);
		internalFrame.getContentPane().add(address);
		address.setColumns(10);
		
		repassword = new JTextField();
		repassword.setBounds(106, 154, 86, 20);
		internalFrame.getContentPane().add(repassword);
		repassword.setColumns(10);
		
		lastname = new JTextField();
		lastname.setBounds(106, 98, 86, 20);
		internalFrame.getContentPane().add(lastname);
		lastname.setColumns(10);
		
		email = new JTextField();
		email.setBounds(106, 179, 86, 20);
		internalFrame.getContentPane().add(email);
		email.setColumns(10);
		
		name = new JTextField();
		name.setBounds(106, 70, 86, 20);
		internalFrame.getContentPane().add(name);
		name.setColumns(10);
		
		JLabel lblPassword = new JLabel("Password");
		lblPassword.setBounds(10, 126, 58, 17);
		internalFrame.getContentPane().add(lblPassword);
		lblPassword.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		JLabel lblPasswordAgain = new JLabel("Password again");
		lblPasswordAgain.setBounds(10, 154, 94, 17);
		internalFrame.getContentPane().add(lblPasswordAgain);
		lblPasswordAgain.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		JLabel lblLastName = new JLabel("Last name");
		lblLastName.setBounds(10, 98, 63, 17);
		internalFrame.getContentPane().add(lblLastName);
		lblLastName.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		JLabel lblAddress = new JLabel("Address");
		lblAddress.setBounds(10, 241, 48, 17);
		internalFrame.getContentPane().add(lblAddress);
		lblAddress.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		JLabel lblEmail = new JLabel("Email");
		lblEmail.setBounds(10, 182, 31, 17);
		internalFrame.getContentPane().add(lblEmail);
		lblEmail.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		JLabel lblName = new JLabel("First name");
		lblName.setBounds(10, 70, 80, 17);
		internalFrame.getContentPane().add(lblName);
		lblName.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		password = new JTextField();
		password.setBounds(106, 126, 86, 20);
		internalFrame.getContentPane().add(password);
		password.setColumns(10);
		
		JLabel lblPermition = new JLabel("Permition");
		lblPermition.setBounds(10, 279, 57, 17);
		internalFrame.getContentPane().add(lblPermition);
		lblPermition.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		telephone = new JTextField();
		telephone.setBounds(106, 210, 86, 20);
		internalFrame.getContentPane().add(telephone);
		telephone.setColumns(10);
		
		final JComboBox comboBox_1 = new JComboBox();
		comboBox_1.setBounds(112, 274, 80, 22);
		internalFrame.getContentPane().add(comboBox_1);
		comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"Manager", "Secretary", "Stockeeper"}));
		
		JLabel lblTelephone = new JLabel("Telephone");
		lblTelephone.setBounds(8, 213, 63, 17);
		internalFrame.getContentPane().add(lblTelephone);
		lblTelephone.setFont(new Font("Tahoma", Font.PLAIN, 14));
		final JButton btnNewButton = new JButton("Add New User");
		btnNewButton.setBounds(53, 302, 139, 37);
		internalFrame.getContentPane().add(btnNewButton);
		btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		final JButton btnUpdateDetails = new JButton("Update details");
		btnUpdateDetails.setBounds(53, 302, 139, 37);
		internalFrame.getContentPane().add(btnUpdateDetails);
		btnUpdateDetails.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

			
				int x = table_7.getSelectedRow();
				if(x > -1)
				{
					ArrayList<String> arrs =new ArrayList<>();
					arrs.clear();
					Object obj = table_7.getModel().getValueAt(x,0);
					arrs.add(obj.toString());
					arrs.add(name.getText());
					arrs.add(password.getText());
					arrs.add(lastname.getText());
					arrs.add(address.getText());
					arrs.add(email.getText());
					arrs.add(telephone.getText());
					int name8=comboBox_1.getSelectedIndex();
					name8=name8+1;
					arrs.add(Integer.toString(name8));
				System.out.print(obj.toString());
				Users u = new Users();
				if(u.updateUsersDetails(arrs)==1)
					{
						
					JOptionPane.showMessageDialog(null, "User Updated Successfully");
					internalFrame.setVisible(false);
					updateusertable();
					}
				else
					JOptionPane.showMessageDialog(null, "Error Update User");	
				}
				else
					JOptionPane.showMessageDialog(null, "Please Select Only User Name");	
			}
		});
		
		
	

		btnUpdateDetails.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		JButton btnUpdate = new JButton("Update");
		btnUpdate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		btnUpdate.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnUpdate.setBounds(53, 302, 139, 37);
		internalFrame.getContentPane().add(btnUpdate);
		
		
		
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				Users u = new Users();
				String name3 = name.getText();
				String name1=username.getText();
				String name2 =password.getText();
				String name4=lastname.getText();
				String name7=address.getText();
				String name5=email.getText();
				String name6=telephone.getText();
				int name8=comboBox_1.getSelectedIndex();
				name8=name8+1;
				ArrayList<String> ar= new  ArrayList<String>();
				ar.add(name1);ar.add(name2);ar.add(name3);ar.add(name4);ar.add(name5);ar.add(name6);ar.add(name7);ar.add(Integer.toString(name8));
				Users ur= new Users();
				ur.adduser(ar);
				 DefaultTableModel model = (DefaultTableModel) table_7.getModel();
				    model.setRowCount(0);
				//TableModel model = table_7.getModel();
				Users us = new Users();
				
				ArrayList<String> res= us.getusers();
				
				for (int i=0; i<=(res.size())-6;i=i+6)
				{
		         Vector<String> row = fill_table(res, i);
			       
			         data.add(row);
			    }
				model.fireTableDataChanged();
				internalFrame.setVisible(false);
			
				
				
			}
		});
		//internalFrame.setVisible(true);
		
		JButton btnDeleteUser = new JButton("Delete User");
		btnDeleteUser.setBackground(new Color(204, 51, 255));
		btnDeleteUser.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnDeleteUser.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				
				int x = table_7.getSelectedRow();
				if(x > -1)
				{
				Object obj = table_7.getModel().getValueAt(x, 0);
				System.out.print(obj.toString());
				Users u = new Users();
				if(u.deleteuser(obj.toString())==1)
					{
						
					JOptionPane.showMessageDialog(null, "User Deleted Successfully");
					internalFrame.setVisible(false);
					updateusertable();
					
					}
				else
					JOptionPane.showMessageDialog(null, "Error Deleting User");	
				}
				else
					JOptionPane.showMessageDialog(null, "Please Select Only User Name");	
			}
		});
		btnDeleteUser.setBounds(533, 361, 149, 38);
		panel_6.add(btnDeleteUser);
		
		JButton btnNewButton_1 = new JButton("Add User");
		btnNewButton_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				username.enable();
				username.setText("");
				password.setText("");
				name.setText("");
				repassword.setText("");
				lastname.setText("");
				address.setText("");
				email.setText("");
				telephone.setText("");
				btnUpdateDetails.setVisible(false);
				btnNewButton.setVisible(true);
				internalFrame.setVisible(true);
								
			}
		});
		btnNewButton_1.setBounds(305, 359, 98, 41);
		panel_6.add(btnNewButton_1);
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(22, 22, 813, 297);
		panel_6.add(scrollPane);
		table_7 = new JTable(data,headers)
		{
            public boolean isCellEditable(int data, int columns)
            {
                if(columns>=1)
         	     return false;
                else return true;
            }
		};
		table_7.setAutoCreateRowSorter(true);
		
		table_7.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				ArrayList<String> ud =new ArrayList<>();
				
				int x = table_7.getSelectedRow();
				if(x > -1)
				{
				Object obj = table_7.getModel().getValueAt(x, 0);
				System.out.print(obj.toString());
				Users us = new Users();
				ud=us.getUserDetails(obj.toString());
				username.setText(ud.get(0));
				password.setText(ud.get(1));
				name.setText(ud.get(2));
				repassword.setText(ud.get(1));
				lastname.setText(ud.get(3));
				address.setText(ud.get(6));
				email.setText(ud.get(4));
				telephone.setText(ud.get(5));
				}
			}
		});
		
		scrollPane.setViewportView(table_7);
		
		JButton btnUpdateDetalis = new JButton("Update Detalis");
		btnUpdateDetalis.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int x = table_7.getSelectedRow();
				if(x > -1)
				{
				username.disable();
				btnUpdateDetails.setVisible(true);
				btnNewButton.setVisible(false);
				internalFrame.setVisible(true);
				}
				else JOptionPane.showMessageDialog(null, "Please select a row ");
			}
		});
		btnUpdateDetalis.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnUpdateDetalis.setBounds(408, 359, 121, 41);
		panel_6.add(btnUpdateDetalis);
		
		JPanel itempanel = new JPanel();
		tabbedPane.addTab("Items", null, itempanel, null);
		itempanel.setLayout(null);
		
		
		itemframe.getContentPane().setBackground(Color.GRAY);
		itemframe.getContentPane().setForeground(Color.GRAY);
		itemframe.setBounds(21, 0, 273, 349);
		itemframe.getContentPane().setFont(new Font("Tahoma", Font.PLAIN, 14));
		itempanel.add(itemframe);
		itemframe.getContentPane().setLayout(null);
		itemframe.setVisible(false);
		final JLabel itemname = new JLabel("Item Name");
		itemname.setFont(new Font("Tahoma", Font.PLAIN, 14));
		itemname.setBounds(10, 25, 79, 24);
		itemframe.getContentPane().add(itemname);
		
		txtitemname = new JTextField();
		txtitemname.setBounds(105, 29, 121, 20);
		itemframe.getContentPane().add(txtitemname);
		txtitemname.setColumns(10);
		
		final JLabel itemdesc = new JLabel("Description");
		itemdesc.setFont(new Font("Tahoma", Font.PLAIN, 14));
		itemdesc.setBounds(10, 70, 79, 24);
		itemframe.getContentPane().add(itemdesc);
		
		txtdesc = new JTextField();
		txtdesc.setBounds(105, 74, 121, 20);
		itemframe.getContentPane().add(txtdesc);
		txtdesc.setColumns(10);
		
		JLabel lblMenufactor = new JLabel("Supplier");
		lblMenufactor.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblMenufactor.setBounds(10, 125, 79, 24);
		itemframe.getContentPane().add(lblMenufactor);
		itemframe.setVisible(false);
		final JButton additem = new JButton("Add Item");
		additem.setFont(new Font("Tahoma", Font.PLAIN, 14));
		additem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				
					ArrayList<String> arrs =new ArrayList<>();
					arrs.clear();
					
					
					arrs.add(txtitemname.getText());
					arrs.add(txtdesc.getText());
					arrs.add((String) comboBoxSupnames.getSelectedItem());
					Items it = new Items();
					try 
					{
						if(it.additem(arrs)==1)
						{
							itemframe.setVisible(false);
							JOptionPane.showMessageDialog(null, "Item add complete");	
						}
							else
							JOptionPane.showMessageDialog(null, "Error Adding Item");	
							
						updateitemstable();
						itemframe.setVisible(false);
					}
					
					catch (SQLException e1) 
					{
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					
					updateItemsCombo(itemsBox);
					updateItemsCombo(itemsBoxCus);
					
			}
		});
		 
		additem.setBounds(72, 269, 113, 32);
		itemframe.getContentPane().add(additem);
		
		final JButton updateitem = new JButton("Update Item");
		updateitem.setFont(new Font("Tahoma", Font.PLAIN, 14));
		updateitem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				int x = itemtable.getSelectedRow();
				ArrayList<String> aritem = new ArrayList<String>();
				Object obj;
				additem.setVisible(false);
				additem.setVisible(false);
				String id,name,menu,desc;
				int id1 ;
				if(x > -1)
				{
					
					obj = itemtable.getModel().getValueAt(x, 1);
					name=obj.toString();
					obj = itemtable.getModel().getValueAt(x, 2);
					desc=obj.toString();
					obj = itemtable.getModel().getValueAt(x, 3);
					menu=obj.toString();
				
					name= txtitemname.getText();
					desc=txtdesc.getText();
					menu=(String) comboBoxSupnames.getSelectedItem();
					Items it = new Items();
				    obj = itemtable.getModel().getValueAt(x, 0);
					id=obj.toString();
					System.out.print("id="+id);
					//id1=Integer.parseInt(id);
					aritem.add(id);aritem.add(name);aritem.add(desc);aritem.add(menu);
					try {
						if(it.updateitem(aritem)==1)
						{
							itemframe.setVisible(false);
							updateitemstable();
							JOptionPane.showMessageDialog(null, "Item Update Compelte");	
							
						}
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					updateItemsCombo(itemsBox);
					updateItemsCombo(itemsBoxCus);
					
				}
				else
				{
					
					JOptionPane.showMessageDialog(null, "Please select only id");	
					
				}
				
			}
		});
		updateitem.setBounds(72, 265, 113, 36);
		itemframe.getContentPane().add(updateitem);
		
	
		JScrollPane itemscrollPane = new JScrollPane();
		itemscrollPane.setBounds(20, 11, 509, 271);
		itempanel.add(itemscrollPane);
		
		itemtable = new JTable(items,itemsheader){
            public boolean isCellEditable(int data, int columns)
            {
                if(columns>=1)
         	     return false;
                else return true;
            }
		};
		itemtable.setAutoCreateRowSorter(true);
		//itemscrollPane.setColumnHeaderView(itemtable);
		itemscrollPane.setViewportView(itemtable);
		
		JButton deleteitemopen = new JButton("Delete Item");
		deleteitemopen.setFont(new Font("Tahoma", Font.PLAIN, 14));
		deleteitemopen.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				int x = itemtable.getSelectedRow();
				additem.setVisible(false);
				additem.setVisible(false);
				String id;
				int id1 ;
				if(x> -1)
				{
					
					Items it = new Items();
					Object obj = itemtable.getModel().getValueAt(x,0);
					id=obj.toString();
					id1=Integer.parseInt(id);
					try {
						if(it.deleteitem(id1)==1)
						{
							itemframe.setVisible(false);
							
						}
						updateitemstable();
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					
					updateItemsCombo(itemsBox);
					updateItemsCombo(itemsBoxCus);
					}
				else
				{
					
					JOptionPane.showMessageDialog(null, "Please select only id");	
					
				}
				
			
			}
		});
		deleteitemopen.setBounds(151, 364, 112, 33);
		itempanel.add(deleteitemopen);
		
		JButton updateitemopen = new JButton("Update Item");
		updateitemopen.setFont(new Font("Tahoma", Font.PLAIN, 14));
		updateitemopen.addActionListener(new ActionListener() {
			@SuppressWarnings("null")
			public void actionPerformed(ActionEvent arg0) {
				
				updateitem.setVisible(true);
				additem.setVisible(false);
				
				int x = itemtable.getSelectedRow();
				additem.setVisible(false);
				
				String id,name,desc,menu;
				ArrayList<String> aritem = new ArrayList<String>();
				int id1 ;
				if(x > -1)
				{
					itemframe.setVisible(true);
					Items it = new Items();
					Object obj = itemtable.getModel().getValueAt(x, 0);
					id=obj.toString();
					//id1=Integer.parseInt(id);
					obj = itemtable.getModel().getValueAt(x, 1);
					name=obj.toString();
					obj = itemtable.getModel().getValueAt(x, 2);
					desc=obj.toString();
					obj = itemtable.getModel().getValueAt(x, 3);
					menu=obj.toString();
					txtitemname.setText(name);
					txtdesc.setText(desc);
					comboBoxSupnames.setSelectedItem(menu);
					aritem.add(id);
					aritem.add(txtitemname.getText());
					aritem.add(txtdesc.getText());
					aritem.add((String) comboBoxSupnames.getSelectedItem());
					//System.out.println(id1);
					/*try {
						if(it.updateitem(aritem)==1)
						{
							
							itemframe.setVisible(false);
							updateitemstable();
							
						}
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}*/
					
					
				}
				else
				{
					
					JOptionPane.showMessageDialog(null, "Please select only id");	
					
				}
				
			}
				
		});
		updateitemopen.setBounds(277, 360, 112, 37);
		itempanel.add(updateitemopen);
		JButton additemopen = new JButton("Add Item");
		additemopen.setFont(new Font("Tahoma", Font.PLAIN, 14));
		additemopen.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				txtitemname.setText("");
				txtdesc.setText("");
				additem.setVisible(true);
				updateitem.setVisible(false);
				itemframe.setVisible(true);
			}
		});
		additemopen.setBounds(31, 364, 110, 33);
		itempanel.add(additemopen);
		
		 reportpanel = new JPanel();
		tabbedPane.addTab("Reports", null, reportpanel, null);
		reportpanel.setLayout(null);
		
		final JInternalFrame reportframe = new JInternalFrame("Reports",true,true,true,true);
		reportframe.setBounds(31, 0, 657, 435);
		reportpanel.add(reportframe);
		reportframe.getContentPane().setLayout(null);
		
		JScrollPane scrollPane_5 = new JScrollPane();
		scrollPane_5.setBounds(20, 39, 524, 322);
		reportframe.getContentPane().add(scrollPane_5);
		
		reporttable = new JTable(report_table,reportheadr);
		/*reporttable.setModel(new DefaultTableModel(
			new Object[][] {
				{null, null},
				{null, null},
			},
			new String[] {
				"New column", "New column"
			}
		));*/
		scrollPane_5.setViewportView(reporttable);
		
		txttotalprice = new JTextField();
		txttotalprice.setFont(new Font("Tahoma", Font.PLAIN, 14));
		txttotalprice.setForeground(new Color(0, 128, 0));
		txttotalprice.setEditable(false);
		txttotalprice.setBounds(357, 372, 105, 25);
		reportframe.getContentPane().add(txttotalprice);
		txttotalprice.setColumns(10);
		
		JLabel lblNewLabel_5 = new JLabel("Total Price:");
		lblNewLabel_5.setBounds(270, 369, 77, 28);
		lblNewLabel_5.setFont(new Font("Tahoma", Font.PLAIN, 14));
		reportframe.getContentPane().add(lblNewLabel_5);
		
		final JLabel lblFrom = new JLabel("From:");
		lblFrom.setFont(new Font("Tahoma", Font.PLAIN, 15));
		lblFrom.setBounds(57, 11, 127, 14);
		reportframe.getContentPane().add(lblFrom);
		
		final JLabel lblto = new JLabel("to");
		lblto.setFont(new Font("Tahoma", Font.PLAIN, 15));
		lblto.setBounds(228, 11, 175, 14);
		reportframe.getContentPane().add(lblto);
		
		JButton btnexport = new JButton("Export");
		btnexport.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				JFileChooser fc = new JFileChooser();
				 int option=fc.showSaveDialog(mainscreen.this);
	                if(option == JFileChooser.APPROVE_OPTION){
	                	 String filename = fc.getSelectedFile().getName(); 
	                     String path = fc.getSelectedFile().getParentFile().getPath();

	 					int len = filename.length();
	 					String ext = "";
	 					String file = "";

	 					if(len > 4){
	 						ext = filename.substring(len-4, len);
	 					}

	 					if(ext.equals(".xls")){
	 						file = path + "\\" + filename; 
	 					}else{
	 						file = path + "\\" + filename + ".xls"; 
	 					}
	 					if(toExcel(reporttable, new File(file))==1)
	 						JOptionPane.showMessageDialog(null, "Report saved");	
	 					else
	 						JOptionPane.showMessageDialog(null, "error eccured while saving the report try again");	
	 				}
	                
				
			}
		});
		btnexport.setBounds(501, 372, 89, 23);
		reportframe.getContentPane().add(btnexport);
		
		final JCalendar startdate = new JCalendar();
		startdate.setBounds(95, 37, 203, 160);
		reportpanel.add(startdate);
		
		
		final JCalendar enddate = new JCalendar();
		enddate.setBounds(390, 38, 203, 160);
		reportpanel.add(enddate);
		String[] s = new String[] {"open order", "closed order", "price"};
		final JComboBox reporton = new JComboBox(s);
		reporton.setModel(new DefaultComboBoxModel(new String[] {"Suppliers open order", "Suppliers closed order", "Suppliers total price", "Customer open order", "Customer closed order", "Customer total price"}));
		reporton.setFont(new Font("Tahoma", Font.PLAIN, 14));
		//reporton.setModel(new DefaultComboBoxModel(new String[] {"open order", "closed order", "price"}));
		reporton.setBounds(145, 231, 181, 23);
		reportpanel.add(reporton);
		
		Button genreport = new Button("generate");
		genreport.setFont(new Font("Dialog", Font.PLAIN, 14));
		genreport.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Date date1,date2 ;
				String status,totalprice;
				Date dsql;
				int price = 0;
				ArrayList<String> ar;
				java.util.Date utilDate = new java.util.Date();
				java.util.Date utilDate1 = new java.util.Date();
				utilDate= startdate.getDate();
				utilDate1= enddate.getDate();
			
				
			    java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
			    java.sql.Date sqlDate1 = new java.sql.Date(utilDate1.getTime());
			    //System.out.println("utilDate:" + utilDate);
			    //System.out.println("sqlDate:" + sqlDate);
				Report r = new Report();
				LineChartDemo6 demo = null;
				
				//Graph1 g = new Graph1();
		       // demo.pack();
		       // RefineryUtilities.centerFrameOnScreen(demo);
		      //  demo.setVisible(true);
				try 
				{
					status=reporton.getSelectedItem().toString();
					if(status.equals("Suppliers total price"))
					{
						status = "closed";
						ar =r.reportsql(sqlDate,sqlDate1,status);
						try 
						{
							demo = new LineChartDemo6("Line Chart Demo 6",ar,sqlDate,sqlDate1);
						} 
						catch (ParseException e1)
						{
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
					}
					else if(status.equals("Suppliers closed order"))
					{
						
						ar =r.getreportclosed(sqlDate,sqlDate1);
						report_table.clear();
						DefaultTableModel model111 = (DefaultTableModel) reporttable.getModel();
						model111.fireTableDataChanged();
						for(int i =0;i<ar.size();i+=6)
						{
							Vector<String> rowso = new Vector<String>();
							rowso.add(ar.get(i)); 
							rowso.add(ar.get(i+1));
							//price += Integer.parseInt(ar.get(i+1));
							rowso.add(ar.get(i+2));
							rowso.add(ar.get(i+3));
							//price += Integer.parseInt(ar.get(i+3));
							rowso.add(ar.get(i+4));
							price += Integer.parseInt(ar.get(i+4));
							rowso.add(ar.get(i+5));
						    report_table.add(rowso);
							
						}
						totalprice = Integer.toString(price);
						txttotalprice.setForeground(new Color(250, 0,0));
						txttotalprice.setText(totalprice);
						lblFrom.setText("From:"+sqlDate.toString());
						lblto.setText("To:"+sqlDate1.toString());
						DefaultTableModel model11 = (DefaultTableModel) reporttable.getModel();
						model111.fireTableDataChanged();
						reportframe.setVisible(true);
						
					}
					else if(status.equals("Suppliers open order"))
					{
						
						ar =r.getreportopen(sqlDate,sqlDate1);
						report_table.clear();
						DefaultTableModel model111 = (DefaultTableModel) reporttable.getModel();
						model111.fireTableDataChanged();
						for(int i =0;i<ar.size();i+=6)
						{
							Vector<String> rowso = new Vector<String>();
							rowso.add(ar.get(i)); 
							rowso.add(ar.get(i+1));
							rowso.add(ar.get(i+2));
							rowso.add(ar.get(i+3));
							rowso.add(ar.get(i+4));
							price += Integer.parseInt(ar.get(i+4));
							rowso.add(ar.get(i+5));
							report_table.add(rowso);
					
						}
						totalprice = Integer.toString(price);
						txttotalprice.setForeground(new Color(250, 0,0));
						txttotalprice.setText(totalprice);
						lblFrom.setText("From:"+sqlDate.toString());
						lblto.setText("To:"+sqlDate1.toString());
						DefaultTableModel model11 = (DefaultTableModel) reporttable.getModel();
						model111.fireTableDataChanged();
						reportframe.setVisible(true);
						
					}
					if(status.equals("Customer total price"))
					{
						status = "closed";
						ar =r.reportsqlcust(sqlDate,sqlDate1,status);
						try 
						{
							demo = new LineChartDemo6("Line Chart Demo 6",ar,sqlDate,sqlDate1);
						} 
						catch (ParseException e1)
						{
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
					}
					else if(status.equals("Customer closed order"))
					{
						
						ar =r.getreportclosedcust(sqlDate,sqlDate1);
						report_table.clear();
						DefaultTableModel model111 = (DefaultTableModel) reporttable.getModel();
						model111.fireTableDataChanged();
						for(int i =0;i<ar.size();i+=6)
						{
							Vector<String> rowso = new Vector<String>();
							rowso.add(ar.get(i)); 
							rowso.add(ar.get(i+1));
							rowso.add(ar.get(i+2));
							rowso.add(ar.get(i+3));
							rowso.add(ar.get(i+4));
							price += Integer.parseInt(ar.get(i+4));
							rowso.add(ar.get(i+5));
							report_table.add(rowso);
							
						}
						totalprice = Integer.toString(price);
						txttotalprice.setForeground(new Color(0,128,0));
						txttotalprice.setText(totalprice);
						lblFrom.setText("From:"+sqlDate.toString());
						lblto.setText("To:"+sqlDate1.toString());
						DefaultTableModel model11 = (DefaultTableModel) reporttable.getModel();
						model111.fireTableDataChanged();
						reportframe.setVisible(true);
						
					}
					else if(status.equals("Customer open order"))
					{
						
						ar =r.getreportopencust(sqlDate,sqlDate1);
						report_table.clear();
						DefaultTableModel model111 = (DefaultTableModel) reporttable.getModel();
						model111.fireTableDataChanged();
						for(int i =0;i<ar.size();i+=6)
						{
							Vector<String> rowso = new Vector<String>();
							rowso.add(ar.get(i)); 
							rowso.add(ar.get(i+1));
							rowso.add(ar.get(i+2));
							rowso.add(ar.get(i+3));
							rowso.add(ar.get(i+4));
							price += Integer.parseInt(ar.get(i+4));
							rowso.add(ar.get(i+5));
							report_table.add(rowso);
						}
						totalprice = Integer.toString(price);
						txttotalprice.setForeground(new Color(0,128,0));
						txttotalprice.setText(totalprice);
						lblFrom.setText("From:"+sqlDate.toString());
						lblto.setText("To:"+sqlDate1.toString());
						DefaultTableModel model11 = (DefaultTableModel) reporttable.getModel();
						model111.fireTableDataChanged();
						reportframe.setVisible(true);
					}
				} 
				catch (SQLException e) 
				{
					
					e.printStackTrace();
				}
				
				
			}
		});
		genreport.setBounds(332, 231, 86, 19);
		reportpanel.add(genreport);
		
		
		
		
		JLabel lblReportOn = new JLabel("Report On");
		lblReportOn.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblReportOn.setBounds(21, 231, 86, 12);
		reportpanel.add(lblReportOn);
		
		JLabel lblStartDate = new JLabel("Start Date");
		lblStartDate.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblStartDate.setBounds(21, 38, 71, 13);
		reportpanel.add(lblStartDate);
		
		JLabel lblEndDate = new JLabel("End Date");
		lblEndDate.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblEndDate.setBounds(309, 36, 71, 17);
		reportpanel.add(lblEndDate);
		reportframe.setVisible(false);
		//itemframe.setVisible(true);
		JLabel label_2 = new JLabel("MTL");
		label_2.setIcon(new ImageIcon("C:\\Users\\300411337\\Desktop\\logos1.png"));
		label_2.setForeground(Color.BLUE);
		label_2.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 45));
		label_2.setBounds(33, 11, 182, 62);
		getContentPane().add(label_2);
		
		
		if(permition.equals("1") || permition.equals("2"))
		{
			panel_6.setEnabled(true);
		}
		else
		{
			
			tabbedPane.setEnabledAt(6, false);
			tabbedPane.setEnabledAt(8, false);
			addorederopen.setEnabled(false);
			btnAddOrder.setEnabled(false);
			
		
		}
		
		
		JLabel lblGoogle = new JLabel("google");
		lblGoogle.setFont(new Font("Tahoma", Font.ITALIC, 16));
		lblGoogle.setBounds(656, 13, 72, 21);
		getContentPane().add(lblGoogle);
		
		JButton btnNewButton_2 = new JButton("Help");
		btnNewButton_2.setBounds(707, 614, 89, 23);
		getContentPane().add(btnNewButton_2);
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				try 
				{
					Process pc = Runtime.getRuntime().exec("cmd.exe /c start http://www.seker.dx.am/mtl");
				} 
					catch (IOException e) 
					{
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
		});
		btnNewButton_2.setFont(new Font("Tahoma", Font.PLAIN, 14));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
	}
	private Vector<Object> creatrow(ArrayList<String> res, int i2) {
		// TODO Auto-generated method stub
		return null;
	}
	Vector<String>  fill_table(ArrayList<String> res,int i)
	{
		
		 Vector<String> row = new Vector<String>();
				
				
		int size=res.size();
		//System.out.print(res);
		row.add(res.get(i)); 
		row.add(res.get(i+1));
		 row.add(res.get(i+2));
		 row.add(res.get(i+3));
		 row.add(res.get(i+4));
		 row.add(res.get(i+5));
		 
		return row;
	}
	public void updatetable()
	{
		Users us = new Users();
		
		 res1= us.getusers();
		
	}
	public void updatetable1()
	{
		Users us = new Users();
		
		ArrayList<String> res= us.getusers();
		
		for (int i=0; i<=(res.size())-6;i=i+6)
		{
	        Vector<String> row = fill_table(res, i);
	       
	         data.add(row);
	    }
		
	}
	public void updateusertable()
	{
		
		DefaultTableModel model = (DefaultTableModel) table_7.getModel();
	    model.setRowCount(0);
	//TableModel model = table_7.getModel();
	Users us = new Users();
	
	ArrayList<String> res= us.getusers();
	
	for (int i=0; i<=(res.size())-6;i=i+6)
	{
     Vector<String> row = fill_table(res, i);
       
         data.add(row);
    }
	model.fireTableDataChanged();
	}
	private static void addPopup(Component component, final JPopupMenu popup) {
		component.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.isPopupTrigger()) {
					showMenu(e);
				}
			}
			public void mouseReleased(MouseEvent e) {
				if (e.isPopupTrigger()) {
					showMenu(e);
				}
			}
			private void showMenu(MouseEvent e) {
				popup.show(e.getComponent(), e.getX(), e.getY());
			}
		});
	}
	public void updateSupllierTable()
	{
		DefaultTableModel model = (DefaultTableModel) table_4.getModel();
	    model.setRowCount(0);
		Suppliers sup = new Suppliers();
		ArrayList<String> ress= sup.getSuppliers();
		for (int i=0; i<=(ress.size())-9;i=i+9)
		{
			Vector<String> rows = new Vector<String>();
				rows.add(ress.get(i)); 
				rows.add(ress.get(i+1));
				rows.add(ress.get(i+2));
				rows.add(ress.get(i+3));
				rows.add(ress.get(i+4));
				rows.add(ress.get(i+5));
				rows.add(ress.get(i+6));
				rows.add(ress.get(i+7));
				rows.add(ress.get(i+8));
			dataSuppliers.add(rows);
		}
		model.fireTableDataChanged();
	}
	public void updateCustomerTable() throws SQLException
	{
		DefaultTableModel model1 = (DefaultTableModel) table_Customers.getModel();
	    model1.setRowCount(0);
		Customers cus = new Customers();
		ArrayList<String> resc= cus.getCustomers();
		for (int i=0; i<=(resc.size())-9;i=i+9)
		{
			Vector<String> rows = new Vector<String>();
				rows.add(resc.get(i)); 
				rows.add(resc.get(i+1));
				rows.add(resc.get(i+2));
				rows.add(resc.get(i+3));
				rows.add(resc.get(i+4));
				rows.add(resc.get(i+5));
				rows.add(resc.get(i+6));
				rows.add(resc.get(i+7));
				rows.add(resc.get(i+8));
			dataCustomers.add(rows);
		}
		model1.fireTableDataChanged();
	}
	Vector<String>  fill_table_items(ArrayList<String> res,int i)
	{
		
		 Vector<String> row = new Vector<String>();
				
				
		int size=res.size();
		//System.out.print(res);
		row.add(res.get(i)); 
		row.add(res.get(i+1));
		 row.add(res.get(i+2));
		 row.add(res.get(i+3));
	
		 
		return row;
	}
	Vector<String>  fill_table_inventory(ArrayList<String> res,int i)
	{
		
		 Vector<String> row = new Vector<String>();
				
				
		int size=res.size();
		//System.out.print(res);
		row.add(res.get(i)); 
		row.add(res.get(i+1));
		 row.add(res.get(i+2));
		 row.add(res.get(i+3));
	
		 
		return row;
	}
	public static boolean isNumeric(String str)
	{
	  return str.matches("-?\\d+(\\.\\d+)?");  //match a number with optional '-' and decimal.
	}
	public void updateOrdersTable()
	{
		SuppliersOrders supO = new SuppliersOrders();
		DefaultTableModel model1 = (DefaultTableModel) table_sup_orders.getModel();
	    model1.setRowCount(0);
		ArrayList<String> resso= supO.getSuppliersOrders();
		for (int i=0; i<=(resso.size())-6;i=i+6)
		{
			Vector<String> rowso = new Vector<String>();
				rowso.add(resso.get(i)); 
				rowso.add(resso.get(i+1));
				rowso.add(resso.get(i+2));
				rowso.add(resso.get(i+3));
				rowso.add(resso.get(i+4));
				rowso.add(resso.get(i+5));
				dataSupOrders.add(rowso);

			
		}
		DefaultTableModel model = (DefaultTableModel) table_sup_orders.getModel();
		model.fireTableDataChanged();
	}
	
	public void updateCusOrdersTable()
	{
		CustomerOrdersLog cusO = new CustomerOrdersLog();
		DefaultTableModel model2 = (DefaultTableModel) table_cus_orders.getModel();
	    model2.setRowCount(0);
		ArrayList<String> rescus= cusO.getCustomersOrders();
		for (int i=0; i<=(rescus.size())-6;i=i+6)
		{
			Vector<String> rowso = new Vector<String>();
				rowso.add(rescus.get(i)); 
				rowso.add(rescus.get(i+1));
				rowso.add(rescus.get(i+2));
				rowso.add(rescus.get(i+3));
				rowso.add(rescus.get(i+4));
				rowso.add(rescus.get(i+5));
				dataCusOrders.add(rowso);

			
		}
		DefaultTableModel model3 = (DefaultTableModel) table_cus_orders.getModel();
		model3.fireTableDataChanged();
		
		
		
	}
	
	
	public void updateitemstable() 
	{
		
			DefaultTableModel model = (DefaultTableModel) itemtable.getModel();
		    model.setRowCount(0);
		
		    Items it = new Items();
		    
		    ArrayList<String> itemres = null;
			try {
				itemres = it.getitems();
			} catch (SQLException e) {
				
				e.printStackTrace();
			}	
			for (int i=0; i<=(itemres.size())-4;i=i+4)
			{
		     Vector<String> row = fill_table_items(itemres, i);
		       
		         items.add(row);
		    }
			model.fireTableDataChanged();
	}
	
	
	public void updateSupCombo(JComboBox<String> supnamebox)
	{
		supnamebox.removeAllItems();
		ArrayList<String> arrSNL=new ArrayList<String>();
		Suppliers combosup =new  Suppliers();
		arrSNL=combosup.getSuppliersNamesList();
		for(int i=0;i<arrSNL.size();i++)
		supnamebox.addItem(arrSNL.get(i));
	}
	
	public void updateItemsCombo(JComboBox<String> itemsBox)
	{
		itemsBox.removeAllItems();
		ArrayList<String> arrIL=new ArrayList<String>();
		Items comboItem =new  Items();
		arrIL=comboItem.getItemNmesList();
		for(int i=0;i<arrIL.size();i+=2)
		{
			itemsBox.addItem(arrIL.get(i)+"-"+arrIL.get(i+1));
		}
	}
	
	public void updateinventorytable() 
	{
		
			DefaultTableModel model = (DefaultTableModel) inventory_table.getModel();
		    model.setRowCount(0);
		
		    Items it = new Items();
		    
		    ArrayList<String> itemres = null;
			try 
			{
				itemres = it.getimventory();
			} 
			catch (SQLException e) 
			{
				
				e.printStackTrace();
			}	
			for (int i=0; i<=(itemres.size())-4;i=i+4)
			{
				Vector<String> row = fill_table_inventory(itemres, i);
				inventory.add(row);
		    }
			model.fireTableDataChanged();
	}
	protected ImageIcon createImageIcon(String path,String description) {
		java.net.URL imgURL = getClass().getResource(path);
		if (imgURL != null)
		{
		return new ImageIcon(imgURL, description);
		}
		else 
		{
		System.err.println("Couldn't find file: " + path);
		return null;
		}
	}
	public int toExcel(JTable table, File file){
		String value ;
		Object obj ;
		try{
			TableModel model = table.getModel();
			FileWriter excel = new FileWriter(file);

			for(int i = 0; i < model.getColumnCount(); i++){
				excel.write(model.getColumnName(i) + "\t");
			}

			excel.write("\n");

			for(int i=0; i< model.getRowCount(); i++) {
					Vector<String> next = report_table.get(i);
				for(int j=0; j < model.getColumnCount(); j++) {
								
						value = next.get(j);
				
					
					excel.write(value+"\t");
				}
				excel.write("\n");
			}

			excel.close();
			return 1;
		}
		catch(IOException e){ System.out.println(e); return 0; }
	}

}

